package com.YiYuanDuoXiangShi;

public class Node {
    double xishu;
    int zhishu;
    Node next;

    public Node() {
        this(0.0,0,null);
    }

    public Node(double xishu, int zhishu) {
       this(xishu,zhishu,null);
    }

    public Node(double xishu, int zhishu, Node next) {
        this.xishu = xishu;
        this.zhishu = zhishu;
        this.next = next;
    }
    public String toString() {
        if (xishu == 0) {
            return "0";  // 对于零系数，直接返回 "0"
        }

        String s = xishu > 0 ? "" : "-";  // 根据系数的正负来初始化字符串，并添加负号（如果需要）
        s += Math.abs(xishu);  // 使用绝对值来确保系数是正数，并添加到字符串中

        if (zhishu > 0) {
            s += "x";  // 添加 "x"
            if (zhishu > 1) {
                s += "^" + zhishu;  // 如果指数大于 1，则添加指数
            }
        }




        return s;
    }
}
